package com.crm.service.impl.opportunityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customerManager.CompetitorMapper;
import com.crm.dao.mapper.customerManager.DemandResearchMapper;
import com.crm.model.entity.customerManager.Competitor;
import com.crm.model.entity.customerManager.CompetitorExample;
import com.crm.model.entity.customerManager.DemandResearch;
import com.crm.model.entity.customerManager.DemandResearchExample;
import com.crm.service.opportunityManager.CompetitorDbService;
import com.crm.service.opportunityManager.DemandResearchDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 需求调研
 */
@Service
public class CompetitorDbServiceImpl implements CompetitorDbService {

    @Autowired
    private CompetitorMapper competitorMapper;

    /**
     * 商机-商机详情-竞品分析
     * @param opportunityId 商机id
     * @param order 分组数据
     * @return
     */
    @Override
    public List<Competitor> competitorList(String opportunityId, String order) {
        CompetitorExample competitorExample = new CompetitorExample();
        CompetitorExample.Criteria criteria = competitorExample.createCriteria();
        competitorExample.setOrderByClause(order);
        criteria.andOpportunityIdEqualTo(opportunityId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Competitor> list = competitorMapper.selectByExample(competitorExample);
        return list;
    }

    /**
     * 商机-商机详情-修改竞品分析
     * @param competitorId 竞品分析id
     * @return
     */
    @Override
    public Competitor getCompetitorById(String competitorId) {
        return competitorMapper.selectByPrimaryKey(competitorId);
    }

    /**
     * 商机详情-修改竞品分析
     * @param competitor 竞品分析实体
     * @return
     */
    @Override
    public Boolean updateCompetitor(Competitor competitor) {
        Boolean result = false;
        int num = competitorMapper.updateByPrimaryKeySelective(competitor);
        if(num>0){
            result = true;
        }
        return result;
    }
}
